import request from '@/axios'
import { Task, TaskGroup } from './types'

export const getTaskFromTicket = (params: any) => {
  return request.get({ url: '/dispatch/tasks', params })
}

export const addTaskPoolApi = (data: any) => {
  return request.post({ url: '/dispatch/task/pool', data })
}

export const getTaskPoolApi = (params: any) => {
  return request.get<Task[]>({ url: '/dispatch/task/pool', params })
}

export const putTaskPoolApi = (data: any) => {
  return request.put({ url: `/dispatch/task/pool/${data.id}`, data })
}

export const getTaskDetailApi = (data: any) => {
  return request.get({ url: `/dispatch/task/pool/${data.ticket_id}` })
}

export const deleteTaskPoolApi = (ids: number[]) => {
  return request.delete({ url: `/dispatch/task/pool`, data: ids })
}

export const exportTaskPoolApi = (ids: string[] | number[]) => {
  return request.post({ url: '/dispatch/task/pool', data: { ids } })
}

export const getTaskGroupTreeApi = (params: any) => {
  return request.get<TaskGroup[]>({ url: '/dispatch/task/tree', params })
}

export const getTaskStatusOptionApi = async () => {
  return request.get({ url: '/dispatch/task/options' })
}

// 问题反馈
export const getTaskFeedbackListApi = (params: any) => {
  return request.get({ url: `/dispatch/task/feedback`, params })
}

export const getTaskFeedbackList2Api = (params: any) => {
  return request.get({ url: `/dispatch/task/feedback2`, params })
}

export const addTaskFeedbackApi = (data: any) => {
  return request.post({ url: '/dispatch/task/feedback', data })
}

export const addTaskFeedbacksApi = (data: any) => {
  return request.post({ url: '/dispatch/task/feedbacks', data })
}

export const putTaskFeedbackApi = (data: any) => {
  return request.put({ url: `/dispatch/task/feedback/${data.id}`, data })
}

export const getTaskFeedbackApi = (data: any) => {
  return request.get({ url: `/dispatch/task/${data.ticket_id}/feedback` })
}

export const deleteTaskFeedbackApi = (ids: string[] | number[]) => {
  return request.delete({ url: '/dispatch/task/feedback', data: ids })
}

export const getFeedbackCategoryOptionsApi = () => {
  return request.get({ url: '/dispatch/task/feedback/options' })
}

// 辅料
export const getTaskNeedListApi = (params: any) => {
  return request.get({ url: `/dispatch/task/need`, params })
}

export const addTaskNeedApi = (data: any) => {
  return request.post({ url: '/dispatch/task/need', data })
}

export const putTaskNeedApi = (data: any) => {
  return request.put({ url: `/dispatch/task/need/${data.id}`, data })
}

export const getTaskNeedApi = (data: any) => {
  return request.get({ url: `/dispatch/task/${data.ticket_id}/need` })
}

export const deleteTaskNeedApi = (ids: string[] | number[]) => {
  return request.delete({ url: '/dispatch/task/need', data: ids })
}

// 外协班组
export const getTaskTeamListApi = (params: any) => {
  return request.get({ url: `/dispatch/task/team`, params })
}

export const addTaskTeamApi = (data: any) => {
  return request.post({ url: '/dispatch/task/team', data })
}

export const putTaskTeamApi = (data: any) => {
  return request.put({ url: `/dispatch/task/team/${data.id}`, data })
}

export const getTaskTeamApi = (data: any) => {
  return request.get({ url: `/dispatch/task/${data.ticket_id}/team` })
}

export const deleteTaskTeamApi = (ids: string[] | number[]) => {
  return request.delete({ url: '/dispatch/task/team', data: ids })
}

// 派工用户列表
export const getTeamUsersApi = (params: any) => {
  return request.get({ url: '/dispatch/task/users', params })
}

// 派工
export const addAssignApi = (data: any) => {
  return request.post({ url: '/dispatch/task/assignment', data })
}

export const deleteAssignApi = (ids: string[] | number[]) => {
  return request.delete({ url: '/dispatch/task/assignment', data: ids })
}

export const getAssignListApi = (params: any) => {
  return request.get({ url: '/dispatch/task/assignment', params })
}

export const getAssignList2Api = (params: any) => {
  return request.get({ url: '/dispatch/task/assignment2', params })
}

// 同步
export const syncTasksApi = (params: any) => {
  return request.get({ url: '/dispatch/task/sync', params })
}

// 远程查询工单
export const queryTaskApi = (params: any) => {
  return request.get({ url: '/dispatch/task/query', params })
}

// 上传下载数据
export const getImportTemplateApi = () => {
  return request.get({ url: '/dispatch/task/template' })
}

export const deleteImportDataApi = (data: any) => {
  return request.delete({ url: '/upload/file', data })
}

export const getTemplateFileApi = () => {
  return request.get({ url: '/dispatch/task/files' })
}

export const exportQueryListApi = (params: any, data: any) => {
  return request.post({ url: '/dispatch/task/export', params, data })
}
